package net.neptech.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import net.neptech.dto.workflow.PageDto;
import net.neptech.mapper.WorkflowGroupMapper;
import net.neptech.model.dto.PageResultDto;
import net.neptech.model.dto.TaskDto;
import net.neptech.model.vo.DataQueryVO;
import net.neptech.model.vo.FormGroupVo;
import net.neptech.service.CombinationGroupService;
import net.neptech.vm.ResponseResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程组聚合接口控制器
 */
@RestController
@RequestMapping( "/combination/group")
@RequiredArgsConstructor
public class CombinationGroupController {
    private final CombinationGroupService combinationGroupService;


    /**
     * 查询表单组包含流程
     */
    @GetMapping("listGroupWithProcess")
    public ResponseResult<List<FormGroupVo>> listGroupWithProcess(Boolean hidden) {
        return ResponseResult.success(combinationGroupService.listGroupWithProcess(hidden));
    }

    /**
     * 查询流程分组和主流程数据
     */
    @GetMapping("listGroupWithProcessMain")
    public ResponseResult<List<FormGroupVo>> listGroupWithProcessMain() {
        return ResponseResult.success(combinationGroupService.listGroupWithProcessMain());
    }

    /**
     * 搜索流程
     */
    @GetMapping("searchFlowList")
    public ResponseResult<List<FormGroupVo.FlowVo>> searchFlowList(String word) {
        return ResponseResult.success(combinationGroupService.searchFlowList(word));
    }

    /**
     * 查询所有我可以发起的表单组
     */
    @GetMapping("listCurrentUserStartGroup")
    public ResponseResult<List<FormGroupVo>> listCurrentUserStartGroup() {
        return ResponseResult.success(combinationGroupService.listCurrentUserStartGroup());
    }

    /**
     * 删除主流程
     */

    @DeleteMapping("deleteProcessMain/{uniqueId}")
    public ResponseResult<Void> deleteProcessMain(@PathVariable String uniqueId) {
        combinationGroupService.deleteProcessMain(uniqueId);
        return ResponseResult.success();
    }

    /**
     * 清理流程
     */
    @DeleteMapping("clear/{uniqueId}")
    public ResponseResult<Void> clear(@PathVariable String uniqueId) {
        combinationGroupService.clear(uniqueId);
        return ResponseResult.success();
    }

    /**
     * 查询当前登录用户的待办任务
     */
    @PostMapping("queryTodoTaskList")
    public ResponseResult<PageResultDto<TaskDto>> queryTodoTaskList(@RequestBody PageDto pageVO) {
        return ResponseResult.success(combinationGroupService.queryTodoTaskList(pageVO));
    }

    /**
     * 查询已办任务
     */
    @PostMapping("queryFinishedTaskList")
    public ResponseResult<PageResultDto<TaskDto>> queryFinishedTaskList(@RequestBody DataQueryVO pageVO) {
        return ResponseResult.success(combinationGroupService.queryFinishedTaskList(pageVO));
    }

    /**
     * 查询已发起的任务
     */
    @PostMapping("queryInitiatedTaskList")
    public ResponseResult<Page> queryInitiatedTaskList(@RequestBody DataQueryVO pageVO) {
        return ResponseResult.success(combinationGroupService.queryInitiatedTaskList(pageVO));
    }

    /**
     * 查询抄送任务
     */
    @PostMapping("queryCopiedTaskList")
    public ResponseResult<Page> queryCopiedTaskList(@RequestBody DataQueryVO pageVO) {
        return ResponseResult.success(combinationGroupService.queryCopiedTaskList(pageVO));
    }
}
